package com.ruoyi.service.jpjs.person.impl;

import com.ruoyi.mapper.jpjs.person.PersonMapper;
import com.ruoyi.service.jpjs.person.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class PersonServiceImpl implements PersonService {
    @Autowired
    private PersonMapper personMapper;

    @Override
    public List<Map<String, Object>> findPersonAll(Map<String, Object> map) {
        return personMapper.findPersonAll(map);
    }

    @Override
    public List<Map<String, Object>> findPersonName(String personType) {
        return personMapper.findPersonName(personType);
    }

    @Override
    public Map<String, Object> findPerson(String id) {
        return personMapper.findPerson(id);
    }

    @Override
    public int savePerson(Map<String, Object> map) {
        int num = 0;
        if (!map.containsKey("id")) {
            num = personMapper.addPerson(map);
        } else {
            num = personMapper.editPerson(map);
        }
        return num;
    }

    @Override
    public int deletePerson(String ids) {
        int count = 0;
        String[] arr = ids.split(",");
        for (String id : arr) {
            count = personMapper.deletePerson(id);
            if (count == 0) {
                return count;
            }
        }
        return count;
    }
}
